"""
案例：
读取03.txt，判断里面有多少个java
"""

f = open("./03.txt", "r", encoding="utf-8")

# 方式一。通过字符串count()方法统计
# ret = f.read()
# count = ret.count("java")
# print(count)

# 方式二：循环一行一行的读取，然后进行判断
num = 0
for line in f:
    line = line.strip()  # 去除换行符
    words = line.split(" ")  # 按空格分割成单词列表
    for word in words:
        if word == "java":
            num += 1

print(f"java出现的次数是：{num}")

f.close()
